import pandas as pd
import numpy as np
import plotly.express as px
import matplotlib.pyplot as plt
print('modules are imported')
dataset_url = 'https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv'
df = pd.read_csv(dataset_url)
df.head()
df.tail()
df.shape
df = df[df.Confirmed > 0]
df.head()
df[df.Country == 'Italy']
fig = px.choropleth(df, locations = 'Country', locationmode='country names', color='Confirmed'
,animation_frame='Date')
fig.update_layout(title_text = 'Global Spread of COVID19')
fig.show()
fig = px.choropleth(df, locations = 'Country', locationmode='country names', color='Deaths'
,animation_frame='Date')
fig.update_layout(title_text = 'Death Rate of COVID19')
fig.show()
df_china = df[df.Country == 'China']
df_china.head()
let's select the columns that we need
df_china = df_china[['Date', 'Confirmed']]
df_china.head()
calculating the first derivation of confrimed column
df_china['Infection Rate'] = df_china['Confirmed'].diff()
df_china.head()
px.line(df_china, x = 'Date', y = ['Confirmed', 'Infection Rate'])
df_china['Infection Rate'].max()
df.head()
countries = list(df['Country'].unique())
max_infection_rates = []
for c in countries :
MIR = df[df.Country == c].Confirmed.diff().max()
max_infection_rates.append(MIR)
df_MIR = pd.DataFrame()
df_MIR['Country'] = countries
df_MIR['Max Infection Rate'] = max_infection_rates
df_MIR.head()
px.bar(df_MIR, x= 'Country', y='Max Infection Rate',
color='Country',
title='Global Maximum Infection Rate')
On 9 March 2020, the government of Italy under Prime Minister Giuseppe Conte imposed a national quarantine, restricting the movement of the population except for necessity, work, and health circumstances, in response to the growing pandemic of COVID-19 in the country. source
italy_lockdown_start_date = '2020-03-09'
italy_lockdown_a_month_later = '2020-04-09'
df.head()
let's get data related to italy
df_italy = df[df.Country == 'Italy']
lets check the dataframe
df_italy.head()
let's calculate the infection rate in Italy
df_italy['Infection Rate'] = df_italy.Confirmed.diff()
df_italy.head()
ok! now let's do the visualization
fig = px.line(df_italy, x= 'Date', y='Infection Rate', title= "Before and After Lockdown Italy")
fig.add_shape(
dict(
type= "line",
x0= italy_lockdown_start_date,
y0= 0,
x1= italy_lockdown_start_date,
y1= df_italy['Infection Rate'].max(),
line = dict(color= 'red', width =2)
)
)
fig.add_annotation(
dict(
x= italy_lockdown_start_date,
y= df_italy['Infection Rate'].max(),
text = 'sharing data of the lockdown'
)
)
fig.add_shape(
dict(
type= "line",
x0= italy_lockdown_a_month_later,
y0= 0,
x1= italy_lockdown_a_month_later,
y1= df_italy['Infection Rate'].max(),
line = dict(color= 'yellow', width =2)
)
)
fig.add_annotation(
dict(
x= italy_lockdown_a_month_later,
y= 0,
text = 'a month later'
)
)
df_italy.head()
let's calculate number of active cases day by day
df_italy['Deaths Rate'] = df_italy.Deaths.diff()
let's check the dataframe again
df_italy.head()
now let's plot a line chart to compare COVID19 national lockdowns impacts on spread of the virus and number of active cases
fig = px.line(df_italy,x='Date',y=['Infection Rate','Deaths Rate'])
fig.show()
let's normalize the columns
df_italy['Infection Rate'] = df_italy['Infection Rate']/df_italy['Infection Rate'].max()
df_italy['Deaths Rate'] = df_italy['Deaths Rate']/df_italy['Deaths Rate'].max()
let's plot the line chart again
fig = px.line(df_italy, x='Date', y=['Infection Rate', 'Deaths Rate'])
fig.add_shape(
dict(
type= "line",
x0= italy_lockdown_start_date,
y0= 0,
x1= italy_lockdown_start_date,
y1= df_italy['Infection Rate'].max(),
line = dict(color= 'green', width =2)
)
)
fig.add_annotation(
dict(
x= italy_lockdown_start_date,
y= df_italy['Infection Rate'].max(),
text = 'sharing data of the lockdown'
)
)
fig.add_shape(
dict(
type= "line",
x0= italy_lockdown_a_month_later,
y0= 0,
x1= italy_lockdown_a_month_later,
y1= df_italy['Infection Rate'].max(),
line = dict(color= 'orange', width =2)
)
)
fig.add_annotation(
dict(
x= italy_lockdown_a_month_later,
y= 0,
text = 'a month later'
)
)
Lockdown was started in Freiburg, Baden-Württemberg and Bavaria on 20 March 2020. Three days later, it was expanded to the whole of Germany
Germany_lockdown_start_date = '2020-03-23'
Germany_lockdown_a_month_later = '2020-04-23'
let's select the data related to Germany
df_germany = df[df.Country == 'Germany']
let's check the dataframe
df_germany.head()
let's calculate the infection rate and deaths rate in Germany
df_germany['Infection Rate'] = df_germany.Confirmed.diff()
df_germany['Deaths Rate'] = df_germany.Deaths.diff()
let's check the dataframe
df_germany.head()
now let's plot the line chart
df_germany['Infection Rate'] = df_germany['Infection Rate']/df_germany['Infection Rate'].max()
df_germany['Deaths Rate'] = df_germany['Deaths Rate']/df_germany['Deaths Rate'].max()
fig = px.line(df_germany, x='Date', y=['Infection Rate', 'Deaths Rate'])
fig.add_shape(
dict(
type= "line",
x0= Germany_lockdown_start_date,
y0= 0,
x1= Germany_lockdown_start_date,
y1= df_germany['Infection Rate'].max(),
line = dict(color= 'black', width =2)
)
)
fig.add_annotation(
dict(
x= Germany_lockdown_start_date,
y= df_germany['Infection Rate'].max(),
text = 'sharing data of the lockdown'
)
)
fig.add_shape(
dict(
type= "line",
x0= Germany_lockdown_a_month_later,
y0= 0,
x1= Germany_lockdown_a_month_later,
y1= df_germany['Infection Rate'].max(),
line = dict(color= 'green', width =2)
)
)
fig.add_annotation(
dict(
x= Germany_lockdown_a_month_later,
y= 0,
text = 'a month later'
)
)